/* POJ1011 */
/*-------- Includes --------*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

/*-------- Global variables --------*/
int parts[65];
bool isUsed[65];
int nOfParts;
int sumOfParts;

/*-------- Function prototypes --------*/
int cmp(const void *a, const void *b);
bool dfs(int iOfParts, int curLen, int tgtLen, int nOfUsed);

/*-------- Main functions --------*/
int main(int argc, char const *argv[])
{
    while (scanf("%d", &nOfParts) != EOF && nOfParts) {
        int lenOfStick;
        int maxOfParts;
        bool isFind = false;

        // Read lengths of sticks parts
        // parts  = malloc(nOfParts * sizeof(int));
        // isUsed = malloc(nOfParts * sizeof(int));
        sumOfParts = 0;
        for (int i = 0; i < nOfParts; i++) {
            scanf("%d", parts + i);
            isUsed[i] = 0;
            sumOfParts += parts[i];
        }

        // Sort parts in descending order
        // cut off
        qsort(parts, nOfParts, sizeof(int), cmp);
        maxOfParts = parts[0];

        for (lenOfStick = maxOfParts; lenOfStick * 2 <= sumOfParts; lenOfStick++) {
            // cut off
            if (sumOfParts % lenOfStick == 0 && dfs(0, 0, lenOfStick, 0)) {
                isFind = true;
                printf("%d\n", lenOfStick);
                break;
            }
        }

        if (!isFind) printf("%d\n", sumOfParts);

        // Release resource
        // free(parts);
        // free(isUsed);
    }

    return 0;
}

/*-------- Functions --------*/
int cmp(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

bool dfs(int iOfParts, int curLen, int tgtLen, int nOfUsed)
{
    // Base case: find a solution
    if (curLen == 0 && nOfUsed == nOfParts) return true;

    int last = -1;
    for (int i = iOfParts; i < nOfParts; i++) {
        // cut off
        if (isUsed[i] || parts[i] == last)
            continue;

        isUsed[i] = true;
        if (curLen + parts[i] < tgtLen) {
            if (dfs(i + 1, curLen + parts[i], tgtLen, nOfUsed + 1))
                return true;
        } else if (curLen + parts[i] == tgtLen) {
            if (dfs(0, 0, tgtLen, nOfUsed + 1))
                return true;
        }

        last = parts[i];

        // Trace back
        isUsed[i] = false;

        // cut off
        if (curLen == 0) break;
    }

    // Can not find a solution
    return false;
}
